import requests
import json

url = "https://odin.sohu.com/odin/api/blockdata"

headers = {
    "Accept": "application/json, text/javascript, */*; q=0.01",
    "Accept-Encoding": "gzip, deflate, br, zstd",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
    "Cache-Control": "no-cache",
    "Content-Type": "application/json;charset=UTF-8",
    "Host": "odin.sohu.com",
    "Origin": "https://www.sohu.com",
    "Pragma": "no-cache",
    "Referer": "https://www.sohu.com/xchannel/TURBd01EQXdPVFV3?spm=smpc.channel_230.block3_34_5Ky52O_1_title.2.1761912217339BYGaNwd_339",
    "Sec-Ch-Ua": "\"Google Chrome\";v=\"141\", \"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"141\"",
    "Sec-Ch-Ua-Mobile": "?0",
    "Sec-Ch-Ua-Platform": "\"Windows\"",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-site",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
    "Cookie": "SUV=1761912421939odinfQlx; clt=1761912422; cld=20251031200702; reqtype=pc; gidinf=x099980109ee1b89673f1d80d000edc9dfdf8d334273; _dfp=pYTIEjSaAyQ; hideAddDesktop=true; t=1761913363336"
}

payload = {
    "pvId": "1761913362599_hCMmQIJ",
    "pageId": "1761913363386_1761912421939odi_h2S",
    "mainContent": {
        "productType": "13",
        "productId": "950",
        "secureScore": "50",
        "categoryId": "41",
        "adTags": "20000077"
    },
    "resourceList": [
        {
            "tplCompKey": "TPLSearch_1_0_pc",
            "content": {
                "requestId": "1761913363118oHk0zhb_950",
                "productId": 268,
                "productType": 14,
                "page": 1,
                "size": 20,
                "pro": "0,1"
            },
            "feedType": "XTOPIC_SYNTHETICAL"
        }
    ]
}

response = requests.post(url, headers=headers, data=json.dumps(payload, ensure_ascii=False), timeout=15)

if response.status_code == 200:
    result = response.json()
    if result.get("success"):
        print("爬取成功！返回数据如下：")
        print(json.dumps(result, ensure_ascii=False, indent=2))
    else:
        print(f"接口返回错误：{result.get('message')}")
        print("当前请求体（供排查）：")
        print(json.dumps(payload, ensure_ascii=False, indent=2))
else:
    print(f"HTTP请求失败，状态码：{response.status_code}")
    print("响应内容：", response.text[:500])